package com.lsc.jdbc.demo.unit.testng.homework;

import com.lsc.jdbc.demo.unit.testng.paramter.util.FileUtils;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class TriangleTest {
    Triangle triangle;

    @BeforeClass
    public void setUp() {
        triangle = new Triangle();
    }


    @Test(dataProvider = "dp2")
    public void test(String a, String b, String c, String exp, String exp_girth, String exp_areas) {
        boolean act = triangle.isTriangle(Double.parseDouble(a), Double.parseDouble(b), Double.parseDouble(c));
        /* 判断  测试是否通过 ？ */
        /* Assert  */
        /* 如果 实际值 和预期值相等 测试 通过  */
        Assert.assertEquals(act, Boolean.parseBoolean(exp));
        /* 判断 测试 结果 是否为 true  如果 为 true  断言通过 */
//        Assert.assertTrue(act,"判断测试结果是否为true：");
        if (act) {
            double act_girth = triangle.girth();
            Assert.assertEquals(act_girth, Double.parseDouble(exp_girth));
        }

        if (act) {
            double act_areas = triangle.areas();
            Assert.assertEquals(act_areas,Double.parseDouble(exp_areas));
        }

    }


    @DataProvider
    public Object[][] dp1() {
        return new Object[][]{
                new Object[]{1.0, 2.0, 4.0, true, 9.0, 6.0},
                new Object[]{2.0, 2.0, 4.0, true, 9.0, 6.0},
                new Object[]{3.0, 4.0, 5.0, true, 12.0, 6.0},
                new Object[]{4.0, 2.0, 4.0, true, 9.0, 6.0},
                new Object[]{5.0, 2.0, 4.0, true, 9.0, 6.0}
        };
    }


    @DataProvider
    public Object[][] dp2() {
        return FileUtils.getFileContent("D:\\CodeSpace\\javaspace\\day01\\src\\com\\lsc\\jdbc\\demo\\unit\\testng\\homework\\triangle.txt");
    }


    @Test
    public void t2() {
        triangle.areas();
    }

}
